<?php
require_once("admin_header.php");
include_once("../fckeditor/fckeditor.php") ;
if (isset($_POST['syear']))
{
	require_once("../include/check_post_key.php");
	$contest_0_start=intval($_POST['syear'])."-".intval($_POST['smonth'])."-".intval($_POST['sday'])." ".intval($_POST['shour']).":".intval($_POST['sminute']).":00";
	$contest_0_end=intval($_POST['eyear'])."-".intval($_POST['emonth'])."-".intval($_POST['eday'])." ".intval($_POST['ehour']).":".intval($_POST['eminute']).":00";
	$contest_1_start=intval($_POST['SRyear'])."-".intval($_POST['SRmonth'])."-".intval($_POST['SRday'])." ".intval($_POST['SRhour']).":".intval($_POST['SRminute']).":00";
	$contest_1_end=intval($_POST['ERyear'])."-".intval($_POST['ERmonth'])."-".intval($_POST['ERday'])." ".intval($_POST['ERhour']).":".intval($_POST['ERminute']).":00";

	
	$contest_0_active=$_POST['checkcontest0'] == 1 ? 'Y' : 'N';
	$contest_1_active=$_POST['checkcontest1'] == 1 ? 'Y' : 'N';
	$title=$_POST['title'];
	$description0=$_POST['description0'];
	$description1=$_POST['description1'];


	$title=mysql_real_escape_string($title);
	$description=mysql_real_escape_string($description);

	$cid=intval($_POST['cid']);
	if(!isset($_SESSION['administrator']) && !isset($_SESSION[$BM_ADMIN])) exit();
	$sql="UPDATE `cr_contest` SET 
	`contest_title`='$title',
	contest_0_description='$description0',
	contest_1_description='$description1',
	`contest_0_start`='$contest_0_start',
	`contest_0_end`='$contest_0_end',
	`contest_1_start`='$contest_1_start',
	`contest_1_end`='$contest_1_end',
	`contest_0_active`='$contest_0_active',
	`contest_1_active`='$contest_1_active'
	WHERE `contest_id`=$cid";

	
	mysql_query($sql) or die(mysql_error());
	
	$sql="DELETE FROM `cr_xmkind` WHERE `contest_id`=$cid";
	mysql_query($sql) or die(mysql_error());
	$xm_kind=trim($_POST['xm_kind']);
	if($contest_1_active == 'Y' && strlen($xm_kind) == 0)
	{
		echo "<script language='javascript'>\n";
		echo "alert('项目竞赛可选项目不能为空!');\n";
		echo "history.go(-1);\n";
		echo "</script>";
		exit(0);
	}
	$pieces = explode(",",$xm_kind );
	if (count($pieces)>0 && strlen($pieces[0])>0)
	{
		$sql_1="INSERT INTO `cr_xmkind`(`xmkind_name`,`contest_id`, `xmkind_num`) 
			VALUES ('$pieces[0]','$cid',1)";
		for ($i=1;$i<count($pieces);$i++)
		{
			$sql_1=$sql_1.",('$pieces[$i]','$cid',$i+1)";
		}

		
		mysql_query($sql_1) or die(mysql_error());
	}
	
	
	echo "<script>window.location.href=\"contest_list.php\";</script>";
	exit();
}
else
{
	$cid=intval($_GET['cid']);
	$sql="SELECT * FROM `cr_contest` WHERE `contest_id`=$cid";
	$result=mysql_query($sql);
	if (mysql_num_rows($result)!=1)
	{
		mysql_free_result($result);
		echo "没有这个比赛!";
		exit(0);
	}
	$row=mysql_fetch_assoc($result);
	$contest_0_start=$row['contest_0_start'];
	$contest_0_end=$row['contest_0_end'];
	$contest_1_start=$row['contest_1_start'];
	$contest_1_end=$row['contest_1_end'];
	$contest_0_active=$row['contest_0_active'];
	$contest_1_active=$row['contest_1_active'];
	$description0=$row['contest_0_description'];
	$description1=$row['contest_1_description'];
	$title=htmlspecialchars($row['contest_title']);
	mysql_free_result($result);
	
	$xm_kind="";
	$sql="SELECT `xmkind_name` FROM `cr_xmkind` WHERE `contest_id`=$cid ORDER BY `xmkind_num`";
	$result=mysql_query($sql) or die(mysql_error());
	for ($i=mysql_num_rows($result);$i>0;$i--)
	{
		$row=mysql_fetch_row($result);
		$xm_kind=$xm_kind.$row[0];
		if ($i>1) $xm_kind=$xm_kind.',';
	}
	
	
	
}
?>

      <div class="fr wid59">
        <h2 class="h2">修改比赛<?php echo $cid;?></h2>
        <div class="middle">
<form method=POST >
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="40" align="left"><strong>包含赛事:
      </strong>
      <input value=1 <?php if($contest_0_active == 'Y') echo "checked";?> type="checkbox" name="checkcontest0" />
<?php echo $sf_name; ?>
<input value=1 <?php if($contest_1_active == 'Y') echo "checked";?> type="checkbox" name="checkcontest1" />
<?php echo $rj_name; ?> </td>
  </tr>
  <tr>
    <td height="40" align="left"><p align="left"><strong>标题:</strong>
          <input name="title" class="inpus1" size="71" value="<?php echo isset($title)?$title:""?>"/>
    </p></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>开始注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left"> 年:
      <input name="syear" class="inpus3" size="4" value=<?php echo substr($contest_0_start,0,4);?> />
月:
<input name="smonth" class="inpus3" size="2" value=<?php echo substr($contest_0_start,5,2);?> />
日:
<input name="sday" class="inpus3" size="2" value=<?php echo substr($contest_0_start,8,2);?> />
时:
<input name="shour" class="inpus3" size="2" value=<?php echo substr($contest_0_start,11,2);?> />
分:
<input name="sminute" class="inpus3" size="2" value=<?php echo substr($contest_0_start,14,2);?> /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>结束注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="eyear" class="inpus3" size="4" value=<?php echo substr($contest_0_end,0,4);?> />
月:
<input name="emonth" class="inpus3" size="2" value=<?php echo substr($contest_0_end,5,2);?> />
日:
<input name="eday" class="inpus3" size="2" value=<?php echo substr($contest_0_end,8,2);?> />
时:
<input name="ehour" class="inpus3" size="2" value=<?php echo substr($contest_0_end,11,2);?> />
分:
<input name="eminute" class="inpus3" size="2" value=<?php echo substr($contest_0_end,14,2)?> /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $sf_name; ?>说明:</strong>
    <?php
	$fck_description = new FCKeditor('description0') ;
	$fck_description->BasePath = '../fckeditor/' ;
	$fck_description->Height = 300 ;
	$fck_description->Width=600;
	$fck_description->Value = $description0;
	$fck_description->Create() ;
	?>
    </td>
  </tr>
 	
	<!-- 
  <tr>
    <td height="40" align="left"><textarea name="textarea" cols="45" rows="5" class="inpus4" id="textarea"></textarea></td>
  </tr>
     -->
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>开始注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="SRyear" class="inpus3" size="4" value=<?php echo substr($contest_1_start,0,4);?> />
月:
<input name="SRmonth" class="inpus3" size="2" value=<?php echo substr($contest_1_start,5,2);?> />
日:
<input name="SRday" class="inpus3" size="2" value=<?php echo substr($contest_1_start,8,2);?> />
时:
<input name="SRhour" class="inpus3" size="2" value=<?php echo substr($contest_1_start,11,2);?> />
分:
<input name="SRminute" class="inpus3" size="2" value=<?php echo substr($contest_1_start,14,2)?> /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>结束注册时间:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left">年:
      <input name="ERyear" class="inpus3" size="4" value=<?php echo substr($contest_1_end,0,4);?> />
月:
<input name="ERmonth" class="inpus3" size="2" value=<?php echo substr($contest_1_end,5,2);?> />
日:
<input name="ERday" class="inpus3" size="2" value=<?php echo substr($contest_1_end,8,2);?> />
时:
<input name="ERhour" class="inpus3" size="2" value=<?php echo substr($contest_1_end,11,2);?> />
分:
<input name="ERminute" class="inpus3" size="2" value=<?php echo substr($contest_1_end,14,2)?> /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>项目（英文字体的&quot;,&quot;隔开，比如“项目1,项目2,项目3”）:</strong></td>
  </tr>
  <tr>
    <td height="40" align="left"><input name="xm_kind" class="inpus1" size="71" value="<?=isset($xm_kind)?$xm_kind:""?>" /></td>
  </tr>
  <tr>
    <td height="40" align="left"><strong><?php echo $rj_name; ?>说明:</strong>
    <?php
	$fck_description = new FCKeditor('description1') ;
	$fck_description->BasePath = '../fckeditor/' ;
	$fck_description->Height = 300 ;
	$fck_description->Width=600;
	$fck_description->Value = $description1;
	$fck_description->Create() ;
	?>
	</td>
  </tr>
  	
	<!-- 
  <tr>
    <td height="40" align="left"><textarea name="textarea2" cols="45" rows="5" class="inpus4" id="textarea2"></textarea></td>
  </tr>
  	 -->
  <tr>
    <td height="40" align="left">
    <input type="image" name="submit" id="submit" src="<?php echo "../template/$BM_TEMPLATE/images/"; ?>02_03-16.jpg"/>
    <input type="image" name="reset" id="reset" src="<?php echo "../template/$BM_TEMPLATE/images/"; ?>06_03.jpg" onclick="this.form.reset(); return false;" /></td>

  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
  <tr>
    <td height="40" align="left">&nbsp;</td>
  </tr>
</table>
    <input type=hidden name='cid' value=<?php echo $cid?>>
	<?php require_once("../include/set_post_key.php");?>
</form>
        </div>
  </div>
     
<?php 
require_once("menu.php");

require_once("./admin_footer.php");

?>

